import { getInitOptions } from '@/config/init'
import { http } from './http'
import { PageQueryParams, PageResponse } from '@/config/page'
import { capitalize } from '@/utils/lang'

/**
 * 获取配置
 * @param entId
 * @returns
 */
export function getProperties () {
  return http().get<any>('/api/account/ignores/properties').then(data => normalize(data))

  function normalize (data: any) {
    if (!data?.deploy) return data
    if (!data?.deploy?.externalDocumentWeb) return data
    const external = new URL(data?.deploy?.externalDocumentWeb).origin
    if (getInitOptions().api !== external) return data
    const keys = ['gateway', 'accountWeb', 'documentWeb', 'documentAdminWeb', 'previewWeb', 'documentMobileH5', 'onlyOfficeWeb']
    keys.forEach(key => {
      data.deploy[key] = data.deploy['external' + capitalize(key)]
    })
    return data
  }
}
